{
 "metadata": {
  "language": "Julia",
  "name": "",
  "signature": "sha256:3481371660b8b7a43d62355b7b2fa5b435755578421ba6041325f936ef0787e4"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Easy to define types"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "immutable Vector2D\n",
      "    x::Float64\n",
      "    y::Float64\n",
      "end"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Vector2D(3,4)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "v = Vector2D(3,4)\n",
      "w = Vector2D(5,6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "v+w"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Addition isn't defined for our new type...\n",
      "\n",
      "but that can be created"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "+(v::Vector2D, w::Vector2D) = Vector2D(v.x+w.x, v.y+w.y)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "v+w"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "*(v::Vector2D, a::Number) = Vector2D(v.x*a, v.y*a)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "v*3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "3*v"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "No assumption that multiplication is commutative..."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "*(a::Number, v::Vector2D) = Vector2D(v.x*a, v.y*a)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "3*v"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "immutable Vector2D{T <: Real}\n",
      "    x::T\n",
      "    y::T\n",
      "end"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Vector2D(3.,4.)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}